<?php

class FavoritosController extends Controller
{
	public $layout='//layouts/map';
	public $propiedades = array();
	public $favoritas;
	public $arrayProp = array();

	
	public function actionIndex()
	{
		
		// ESTE ARRAY ES EL PRINCIPAL - Hay que lograr que cargue los objetos
		// TipoPropiedad
		//$this->propiedades = Propiedad::model()->with('favoritas')->findAll();
		//$this->propiedades = Yii::app()->user->id
		$this->favoritas = Favorita::model()->findAllByAttributes(array('usuario'=>Yii::app()->user->id));
		
		foreach ($this->favoritas as $favo){
			array_push($this->propiedades, $favo->propiedad0);
		}
		
		foreach($this->propiedades as $Prop){
			$tipo=$Prop->tipoPropiedad;
			$zona=$Prop->zona0;
			$publis=$Prop->publicacions;
			$aux = array (
							  "id" => $Prop->id,
							  "lat" => $Prop->lat,
							  "lng" => $Prop->lng,
						 	  "descripcion" => $Prop->descripcion,
                              "zona" => $Prop->zona,
                              "antiguedad" => $Prop->antiguedad,
							  "habitaciones" => $Prop->habitaciones,
							  "banios" => $Prop->banos,
							  "descripcion_breve" => $Prop->descripcion_breve,
							  "tipoPropiedad" => $tipo->nombre,
							  "zona" => $zona->nombre,
							  "pubs" => $publis,
        	);
			array_push($this->arrayProp, $aux);			
		}
		
		
		$this->render('index');
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}